package com.gimi.cloud.jimi.commonService.util;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletContext;

import com.gimi.cloud.jimi.common.utils.StringUtil;
import com.gimi.cloud.jimi.commonService.service.CoreApiConfigService;
import com.gimi.cloud.jimi.entity.core.ApiConfig;
import org.apache.log4j.Logger;

public class InitGlobal {


	private static Logger logger = Logger.getLogger(InitGlobal.class);

	public static void init(ServletContext context) {
		// ApplicationContext ctx =
		// WebApplicationContextUtils.getRequiredWebApplicationContext(context);

		/**
		 * API配置文件
		 */
		CoreApiConfigService apiConfigService = (CoreApiConfigService) BeanUtil.getBean("coreApiConfigService");
		List<ApiConfig> apiConfigs = apiConfigService.getValidateApi();
		Map<String, ApiConfig> apiConfigMap = new HashMap<String, ApiConfig>();
		for (ApiConfig apiConfig : apiConfigs) {
			if (StringUtil.isNotBlank(apiConfig.getNid())) {
				apiConfigMap.put(apiConfig.getNid(), apiConfig);
			}
		}
		Global.API_CONFIG = apiConfigMap;
        
	}

}
